using System.Collections.Generic;
using System.Collections.ObjectModel;
using ibba.src.noriskbo.Models;
using ibba.src.noriskbo.ServicePortfolio;

namespace ibba.src.noriskbo.code.translate
{
    public class PortfolioTL
    {
        #region Translate PortfolioDC To Portfolio

        public static void TranslatePortfolioDCToPortfolio(PortfolioDC pRequest, Portfolio pResponse)
        {
            pResponse.IdPortfolio = pRequest.IdPortfolio;
            pResponse.IdISDA = (pRequest.IdISDA == 0) ? null : (int?)pRequest.IdISDA;
            pResponse.CdContrato = pRequest.CdContrato;
            pResponse.IdOperacao = (pRequest.IdOperacao == 0) ? null : (int?)pRequest.IdOperacao;
            pResponse.dtPortfolio = pRequest.dtPortfolio;
            pResponse.VlThreshold = pRequest.VlThreshold;
            pResponse.VlMTA = pRequest.VlMTA;
            pResponse.VlPrazo = pRequest.VlPrazo;
            pResponse.PcHaircut = pRequest.PcHaircut;
            pResponse.VlMargem = pRequest.VlMargem;
            pResponse.CdMoeda = pRequest.CdMoeda;
            
            pResponse.DtIniVig = pRequest.DtIniVig;
            pResponse.DtFimVig = pRequest.DtFimVig;

            pResponse.dtPortfolio = pRequest.dtPortfolio;

            pResponse.ListaClientes = PortfolioClienteTL.TranslatePortfolioClienteDCToPortfolioCliente(pRequest.ListaClientes);
        }

        public static Portfolio TranslatePortfolioDCToPortfolio(PortfolioDC pRequest)
        {
            Portfolio response = new Portfolio();

            TranslatePortfolioDCToPortfolio(pRequest, response);

            return response;
        }

        public static List<Portfolio> TranslatePortfolioDCToPortfolio(List<PortfolioDC> pRequest)
        {
            List<Portfolio> response = new List<Portfolio>();

            foreach (PortfolioDC item in pRequest)
                response.Add(TranslatePortfolioDCToPortfolio(item));

            return response;
        }

        #endregion

        #region Translate Portfolio To PortfolioDC

        public static void TranslatePortfolioToPortfolioDC(Portfolio pRequest, PortfolioDC pResponse)
        {
            pResponse.IdPortfolio = pRequest.IdPortfolio;
            pResponse.CdContrato = pRequest.CdContrato;
            pResponse.IdOperacao = (pRequest.IdOperacao == null) ? 0 : (int)pRequest.IdOperacao;
            pResponse.IdISDA = (pRequest.IdISDA == null) ? 0 : (int)pRequest.IdISDA;
            pResponse.dtPortfolio = pRequest.dtPortfolio;
            pResponse.VlThreshold = pRequest.VlThreshold;
            pResponse.VlMTA = pRequest.VlMTA;
            pResponse.VlPrazo = pRequest.VlPrazo;
            pResponse.PcHaircut = pRequest.PcHaircut;
            pResponse.VlMargem = pRequest.VlMargem;
            pResponse.CdMoeda = pRequest.CdMoeda;

            pResponse.DtIniVig = pRequest.DtIniVig;
            pResponse.DtFimVig = pRequest.DtFimVig;

            pResponse.ListaClientes = PortfolioClienteTL.TranslatePortfolioClienteToPortfolioClienteDC(pRequest.ListaClientes);
        }

        public static PortfolioDC TranslatePortfolioToPortfolioDC(Portfolio pRequest)
        {
            PortfolioDC response = new PortfolioDC();

            TranslatePortfolioToPortfolioDC(pRequest, response);

            return response;
        }

        public static List<PortfolioDC> TranslatePortfolioToPortfolioDC(List<Portfolio> pRequest)
        {
            List<PortfolioDC> response = new List<PortfolioDC>();

            foreach (Portfolio item in pRequest)
                response.Add(TranslatePortfolioToPortfolioDC(item));

            return response;
        }

        #endregion

        #region Translate PortfolioGrid To PortfolioDC

        public static void TranslatePortfolioToPortfolioDC(PortfolioGrid pRequest, PortfolioDC pResponse)
        {
            pResponse.IdPortfolio = pRequest.IdPortfolio;
            pResponse.CdContrato = pRequest.CdContrato;
            pResponse.IdOperacao = (pRequest.IdOperacao == null) ? 0 : (int)pRequest.IdOperacao;
            pResponse.IdISDA = (pRequest.IdISDA == null) ? 0 : (int)pRequest.IdISDA;
            pResponse.dtPortfolio = pRequest.dtPortfolio;
            pResponse.VlThreshold = pRequest.VlThreshold;
            pResponse.VlMTA = pRequest.VlMTA;
            pResponse.VlPrazo = pRequest.VlPrazo;
            pResponse.PcHaircut = pRequest.PcHaircut;
            pResponse.VlMargem = pRequest.VlMargem;
            pResponse.CdMoeda = pRequest.CdMoeda;

            pResponse.DtIniVig = pRequest.DtIniVig;
            pResponse.DtFimVig = pRequest.DtFimVig;

            switch (pRequest.StatusImportacao)
            {
                case ibba.src.noriskbo.Constantes.StatusPortfolioImportLote.GRAVADO:
                    pResponse.StatusImportacao = 0;
                    break;

                case ibba.src.noriskbo.Constantes.StatusPortfolioImportLote.INCLUSAO:
                    pResponse.StatusImportacao = 1;
                    break;

                case ibba.src.noriskbo.Constantes.StatusPortfolioImportLote.INCLUSAO_AVISO:
                    pResponse.StatusImportacao = 1;
                    break;

                case ibba.src.noriskbo.Constantes.StatusPortfolioImportLote.ALTERACAO:
                    pResponse.StatusImportacao = 2;
                    break;

                case ibba.src.noriskbo.Constantes.StatusPortfolioImportLote.ALTERACAO_AVISO:
                    pResponse.StatusImportacao = 2;
                    break;

                case ibba.src.noriskbo.Constantes.StatusPortfolioImportLote.EXCLUSAO:
                    pResponse.StatusImportacao = 3;
                    break;

                default:
                    pResponse.StatusImportacao = 0;
                    break;
            }

            pResponse.ListaClientes = PortfolioClienteTL.TranslatePortfolioClienteToPortfolioClienteDC(pRequest.ListaClientesGrid);
        }

        public static PortfolioDC TranslatePortfolioToPortfolioDC(PortfolioGrid pRequest)
        {
            PortfolioDC response = new PortfolioDC();

            TranslatePortfolioToPortfolioDC(pRequest, response);

            return response;
        }

        public static List<PortfolioDC> TranslatePortfolioToPortfolioDC(ObservableCollection<PortfolioGrid> pRequest)
        {
            List<PortfolioDC> response = new List<PortfolioDC>();

            foreach (PortfolioGrid item in pRequest)
                response.Add(TranslatePortfolioToPortfolioDC(item));

            return response;
        }

        #endregion
    }
}
